package com.sylli.oeuf.server.object.transferable;

import java.util.ArrayList;
import java.util.List;

public class PostNPCConversationLogicTO extends PostResponseTO {

	/**
	 * 
	 */
	private static final long serialVersionUID = -3311154436083778198L;
	
	private List<ConversationEntryTO> entities = new ArrayList<ConversationEntryTO>();

	public PostNPCConversationLogicTO() {
		// for flex uses.
	}
	
	/**
	 * Startup the PostNPCConversationLogicTO class with 
	 * predefine formatted version text.
	 * 
	 * Text must follows the following rules.
	 * 
	 * Each entities must be separated with %be%
	 * Each attributes in each entities must be separated with %ba%
	 * 
	 * @param formattedText
	 */
	public void setupEntites(String formattedText) {
		for (String ent : formattedText.split("%be%")) {
			int id = 0;
			String statement = null;
			String choices = null;
			int count = 0;
			for (String s : ent.split("%ba%")) {
				switch (count) {
				case 0:
					id = Integer.parseInt(s);
					break;
				case 1:
					statement = s;
					break;
				case 2:
					choices = s;
					break;
				default:
				}
				count ++;
			}
			this.addEntity(id, statement, choices);
		}
	}
	
	public void addEntity(int id, String statement, String choices) {
		entities.add(new ConversationEntryTO(id, statement, choices));
	}
	
	public List<ConversationEntryTO> getEntities() {
		return entities;
	}

	public void setEntities(List<ConversationEntryTO> entities) {
		this.entities = entities;
	}
	
	@Override
	public String toString() {
		return "PostNPCConversationTO: " + entities;
	}
		
}
